﻿using AntDesign;
using Microsoft.AspNetCore.Components;
using Sky.App.AI;

namespace Sky.App.AIUI.Pages
{
    public partial class Chat
    {
        #region 变量声明

        [Inject] protected MessageService Message { get; set; } = default!;
        protected List<DeepSeek.MessageItem> MessageList = [];
        protected string? _messageInput;
        protected bool _isLoading = false;

        #endregion 变量声明

        #region 页面事件

        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
            }
        }

        #endregion 页面事件

        #region 操作事件

        protected async Task OnSendAsync()
        {
            if (string.IsNullOrWhiteSpace(_messageInput))
            {
                _ = Message.Info("请输入消息", 2);
                return;
            }

            var list = await DeepSeek.SendAsync(_messageInput, MessageList);
            MessageList = list;
            _messageInput = string.Empty;
        }

        protected async Task OnCopyAsync(DeepSeek.MessageItem item)
        {
            await Task.Run(() =>
            {
                _messageInput = item.Questions;
            });
        }

        protected async Task OnClearAsync(string id)
        {
            await Task.Run(() =>
            {
                MessageList = MessageList.Where(w => w.ID != id).ToList();
            });
        }

        #endregion 操作事件
    }
}